package com.ht.power3d;

import javax.media.opengl.GLCanvas;
import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 *
 * @author: zhangde
 * Date: 2009-2-24
 */
public class CanvasTips {
    private AbstractGL abstractGL;
    private PopupMenu popupMenu = new PopupMenu();
    private String toShow;

    public CanvasTips(AbstractGL abstractGL, String toShow) {
        this.toShow = toShow;
        this.abstractGL = abstractGL;
    }

    public CanvasTips(AbstractGL abstractGL) {
        this.abstractGL = abstractGL;
    }

    public AbstractGL getAbstractGL() {
        return abstractGL;
    }

    public void setAbstractGL(AbstractGL abstractGL) {
        this.abstractGL = abstractGL;
    }

    public PopupMenu getPopupMenu() {
        return popupMenu;
    }

    public void setPopupMenu(PopupMenu popupMenu) {
        this.popupMenu = popupMenu;
    }

    public String getToShow() {
        return toShow;
    }

    public void setToShow(String toShow) {
        this.toShow = toShow;
    }

    public void displayTips() {
        String[] toShowSplit = toShow.split("\n");
        if (toShowSplit != null && toShowSplit.length > 0) {
            for (int i = 0; i < toShowSplit.length; i++) {
                MenuItem menuItem = new MenuItem(toShowSplit[i]);
                popupMenu.add(menuItem);
            }
        }
        abstractGL.getGLCanvas().add(popupMenu);
        popupMenu.show(abstractGL.getGLCanvas(), abstractGL.getPickMouseX(), abstractGL.getPickMouseY());
    }

    public static PopupMenu displayMine(String toShow, GLCanvas canvas, int x, int y) {
        String[] toShowSplit = toShow.split("\n");
        PopupMenu popupMenu = new PopupMenu();
        if (toShowSplit != null && toShowSplit.length > 0) {
            for (int i = 0; i < toShowSplit.length; i++) {
                MenuItem menuItem = new MenuItem(toShowSplit[i]);
                popupMenu.add(menuItem);
            }
        }
        canvas.add(popupMenu);
        popupMenu.show(canvas, x, y);
        return popupMenu;
    }

}
